package com.itheima.crm.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import com.itheima.crm.domain.Customer;

@Repository
public interface CustomerRepository extends JpaRepository<Customer, Integer>,JpaSpecificationExecutor<Customer>{

	List<Customer> findByFixedAreaIdIsNull();

	List<Customer> findByFixedAreaId(String fixedAreaId);
	
	@Query("update Customer set fixedAreaId = null where fixedAreaId = ?1")
	@Modifying
	void clearByFixedAreaId(String fixedAreaId);

	@Query("update Customer set fixedAreaId = ?1 where id = ?2")
	@Modifying
	void updateByFixedAreaId(String fixedAreaId, Integer id);

	Customer findByTelephone(String telephone);

	@Query("update Customer set type = 1 where telephone = ?1")
	@Modifying
	void updateByTelephone(String telephone);

	Customer findByTelephoneAndPassword(String telephone, String password);

}
